package cn.newhopedairy.auth.authentication;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * @author Neo.Li
 * @date 2020-12-3115:51
 */
public class UserDetailsServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return null;
    }

//    @Autowired
//    private IUserService userService;
//
//    @Autowired
//    private IRoleService roleService;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        //查询用户
//        LambdaQueryWrapper<UserPo> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(UserPo::getUsername, username);
//        UserPo user = userService.getOne(wrapper);
//        if (user == null) {
//            throw new UsernameNotFoundException("帐号：" + username + " 不存在！");
//        }
//        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
//
//        //查询拥有的角色
//        List<RolePo> roles = roleService.list();
//        roles.forEach(r -> {
//            //security的验证规则需要ROLE_，由于数据库里存的是vip1、vip2、vip3这种值，需要加上ROLE_
//            grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + r.getRoleName()));
//        });
//        return new User(user.getUsername(), user.getPassword(), grantedAuthorities);
//    }

}